package com.yupi.springbootinit.model.dto.reverse;

import com.yupi.springbootinit.utils.ServerMetricsUtil;
import lombok.Data;

/**
 * @TODO 反向压力
 */
@Data
public class ServerLoadInfo {

    /**
     * cpu阈值
     */
    private double cpuUsage;

    /**
     * 内存阈值
     */
    private double memoryUsage;

    boolean isHighLoad;

    public ServerLoadInfo(double cpuUsagePercentage, double memoryUsagePercentage) {
        this.cpuUsage = cpuUsagePercentage;
        this.memoryUsage = memoryUsagePercentage;
        System.out.println("CPU："+cpuUsage+"内存："+memoryUsage);
    }

    public ServerLoadInfo() {
    }

    /**
     * 非常高负载
     * 不在接收任何任务
     * @return boolean
     */
    public boolean isVeryHighLoad() {
        return cpuUsage > 90 || memoryUsage > 80; // CPU > 90%, 内存 > 80%
    }

    /**
     * 高负载
     * 使用消息队列进行任务
     * @return boolean
     */
    public boolean isHighLoad() {
        return cpuUsage > 50 || memoryUsage > 50; // CPU > 80% or 内存 > 70%
    }

    /**
     * 中等负荷 其他状态
     * 使用线程异步进行任务
     * @return boolean
     */
    public boolean isMediumLoad() {
        return cpuUsage < 50 || memoryUsage < 50; // CPU > 30%, 内存 > 30%
    }
}
